<template>
	<view>
		<view v-if="Infomation!=''">
			<!-- 学生 -->
			<view class="content">
				<view class="aui-news-box">
					<view href="javascript:;" class="aui-news-item" v-for="(item, index) in notice" :key="index" @click="topath(index,item.senderType,item.nrId,item.cdate)">
						<!-- 有数据时候显示 -->
						<view class="radiu" v-show="item.read != 1"></view>
						<div class="aui-news-item-hd">
							<image src="../../static/img/my/gonggao.png" alt="" style="width: 100upx; height: 100upx;" v-show="item.senderType == 0"></image>
							<image src="../../static/img/my/shenhe.png" alt="" style="width: 100upx; height: 100upx;" v-show="item.senderType == 1"></image>
							<image src="../../static/img/my/notice1.png" alt="" style="width: 100upx; height: 100upx;" v-show="item.senderType == 2"></image>
						</div>
						<div class="aui-news-item-bd">
							<h4>{{item.title}}</h4>
							<p>{{item.content}}</p>
						</div>
						<span class="aui-news-item-fr">{{item.cdate}}</span>
					</view>
				</view>
			</view>
			<!-- 教师和企业 -->
			<!-- <view class="aui-news-box" v-show="data == true">
				<view href="javascript:;" class="aui-news-item" v-for="(item, index) in notice" :key="index" @click="topath(index,item.senderType,item.nrId)">
					<view class="radiu" v-show="item.read != 1"></view>
					<div class="aui-news-item-hd">
						<image src="../../static/img/my/notice1.png" alt="" style="width: 100upx; height: 100upx;"></image>
					</div>
					<div class="aui-news-item-bd">
						<h4>{{item.title}}</h4>
						<p>{{item.content}}</p>
					</div>
					<span class="aui-news-item-fr" >{{item.cdate}}</span>
				</view>
			</view> -->
			<view class="none" v-show="show">
				<image src="../../static/img/my/zanwu1.png" style="width: 123px;height: 95px;"></image>
				<text>暂无数据</text>
			</view>
		</view>
		<view v-else>
			<nodataView></nodataView>
		</view>
	</view>

</template>

<script>
	import nodataView from '@/components/nodataView/nodataView.vue'
	import {
		changeStatus,
		getMsgsReceive
	} from '@/api/my/service.js';
	export default {
		components:{
			nodataView
		},
		data() {
			return {
				notice: [],
				show: "",
				Infomation: null
			}
		},
		onLoad(option) {
			this.Infomation = uni.getStorageSync("Infomation");
			console.log(this.Infomation, "---------")
			this.change();
		},
		methods: {
			topath(index, senderType, nrId, cdate) {
				uni.navigateTo({
					url: 'company/noticedetail?index=' + index + '&senderType=' + senderType + '&cdate=' + cdate,
				});
				//console.log("----"+cdate);
				//改变已读状态 接口以调用(怎么实时更新已读状态)
				changeStatus(nrId).then(res => {
					this.notice[index].read = 1;
					console.log("change" + res);
				}).catch(res => {
					console.log("nochange" + res);
				})
			},
			change() {
				this.notice = uni.getStorageSync("notice");
				// var notice = uni.getStorageSync("notice");
				if (this.notice.length == 0) {
					this.show = true;
				} else {
					this.show = false;
				}
				//
				console.log(this.notice + "----" + this.notice.length + "----");
				var timestamp = Date.parse(new Date());
				if (this.notice != 0) {
					for (var i = 0; i < this.notice.length; i++) {
						console.log(this.notice[i].cdate);
						var date = new Date(this.notice[i].cdate.replace(/-/g, "/"));
						console.log(timestamp + "----" + date);
						var diff = (timestamp - date) / 1000;
						var day = parseInt(diff / (60 * 60 * 24));
						var hou = parseInt(diff % (60 * 60 * 24) / 3600);
						var min = parseInt(diff % (60 * 60 * 24) % 3600 / 60);
						var sec = parseInt(diff % (60 * 60 * 24) % 3600 % 60);
						if (day > 0) {
							console.log(day + "天前");
							this.notice[i].cdate = day + "天前";
						} else if (day <= 0 && hou > 0) {
							console.log(hou + "小时前");
							this.notice[i].cdate = hou + "小时前";
						} else if (day <= 0 && hou <= 0 && min > 0) {
							console.log(min + "分钟前");
							this.notice[i].cdate = min + "分钟前";
						} else if (day <= 0 && hou <= 0 && min <= 0 && sec > 0) {
							console.log(sec + "刚刚");
							this.notice[i].cdate = "刚刚";
						}
						console.log(diff + "----" + day + "-----" + hou + "-----" + min + "-----" + sec + "----" + this.notice[i].cdate);
					}
				}
			},
		}
	}
</script>

<style>
	@import './css/style.css';

	.radiu {
		/*标记已读和未读*/
		position: absolute;
		left: 110rpx;
		width: 10rpx;
		height: 10rpx;
		background-color: rgba(239, 45, 45, 1);
		border-radius: 50%;
		top: 40rpx;
	}

	.none {
		text-align: center;
		position: relative;
		top: 100px;
	}

	.none text {
		font-size: 14pt;
		position: absolute;
		top: 120px;
		left: 40%;
	}
</style>
